package com.atguigu.springmvc.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.springmvc.entity.User;
import com.atguigu.springmvc.utils.JsonUtils;
import com.google.common.collect.Lists;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.time.LocalDateTime;
import java.util.Date;
import java.util.List;

/**
 * @author : wenchao.long
 * @date : Created in 2020/11/04 16:00 周三
 * @description :
 */
@RestController
public class UserController {

    @RequestMapping("j1")
    public String json1() {
        User user = new User().setAge(1).setName("龙").setSex("nan");
        Object o = JSON.toJSON(user);
        System.out.println(o);
        return o.toString();
    }

    @RequestMapping("j2")
    public String json2() {
        List<User> userList = Lists.newArrayList(
                new User("龙", 22, "男"),
                new User("文", 22, "男"),
                new User("超", 22, "男")
        );

        return JsonUtils.getJson(userList);
    }

    @RequestMapping("j3")
    public String json3() {
        LocalDateTime localDateTime = LocalDateTime.now();

        return JsonUtils.getJson(localDateTime);
    }

    @RequestMapping("j4")
    public String json4() {
        return JsonUtils.getJson(new Date());
    }

    @RequestMapping("j5")
    public String json5() {
        List<User> userList = Lists.newArrayList(
                new User("龙", 22, "男"),
                new User("文", 22, "男"),
                new User("超", 22, "男")
        );
        return JSON.toJSONString(userList);
    }
}
